﻿package component.tree.web.view;

import java.util.List;

import component.tree.util.ConfigUtil;
import component.tree.util.StringUtil;


//树型选择框模板
public class TreeSelectView extends TreeView {
	
	public TreeSelectView(){
		super();
	}

	public TreeSelectView(String context,List treeList){
		super(context, treeList);
	}
	
	public TreeSelectView(String treeObj,String context,List treeList){
		super(treeObj, context, treeList);
	}
	
	public String toString(){
		String treeView = super.toString();
		
		String attribute = "";
		StringBuffer sb = new StringBuffer(10000);
		String importLib = "";
		if(StringUtil.isNull(title)) title = "树型选择";
		this.setHeadHtml(sb,title, importLib);
		
		//需要在这里引入,不然刷新的时候引入不了样式
		sb.append(ConfigUtil.getImportTreeJs());
		sb.append(ConfigUtil.getImportTreeCss());
		
		this.startBody(sb, " class='bodybg-gray' ");
		
		//生成按钮开始
		this.startTable(sb,attribute);
		this.startTr(sb, attribute);
		this.startTd(sb, "nowrap='nowrap'");
		
		if(this.isShowFirstBtn()){
			String firstName = "展开";
			if(this.firstShowLevel>1) firstName = "收起";
			this.setButtonHtml(sb,"expendId", firstName, "eval('" + this.treeObj + ".changeAllState2()')");this.setLineBreak(sb);
			//this.setButtonHtml(sb, "刷新", "eval('"+this.treeObj+".doRefresh()')");this.setLineBreak(sb);
		}
		if(this.isShowClearBtn()){
			this.setButtonHtml(sb, "重置", "eval('"+this.treeObj+".doClear()')");this.setLineBreak(sb);
		}
		this.setButtonHtml(sb, "确定", "eval('"+this.treeObj+".doOK()')");this.setLineBreak(sb);
		this.setButtonHtml(sb, "关闭", "window.close();");this.setLineBreak(sb);
		
		this.endTd(sb);
		this.endTr(sb);
		this.endTable(sb);
		//生成按钮结束
		
		sb.append("<hr>");
		
		//搜索条件开始
		if(this.isSearch){
			sb.append("<span class='input-normal-two'>");
			String onkeypress = "eval('"+this.treeObj+".toSearch()')";
			sb.append("名称：<input size='15' type='text' name='searchName' onkeypress=\"" + onkeypress + "\" value='"+this.searchName+"' />");
			sb.append("</span>");
			this.setLineBreak(sb);
			this.setButtonHtml(sb,"search", "搜索", "eval('"+this.treeObj+".doSearch()')");this.setLineBreak(sb);
			this.setLineBreak(sb);
			sb.append("<br><br>");
			this.setLineBreak(sb);
		}
		//搜索条件结束
		
		//树型数据显示
		sb.append("<div id='treeDivId'>");
		sb.append(treeView);
		sb.append("</div>");
		
		this.endBody(sb);
		
		//脚本方法开始
		this.startScript(sb);
		sb.append(this.treeObj+".selectCheckboxByIds('"+this.selectIds+"');");
		this.endScript(sb);
		//脚本方法结束
		
		return sb.toString();
	}

	
}
